import requests
import re
import gzip
import subprocess
import ssl
import time
import pymysql
from pythonTestDouyin.DouyinAutoAcceptBulletChat.p1_pb2 import PushFrame,Response,RoomStatsMessage,RoomDataSyncMessage,RoomRankMessage,MemberMessage,LikeMessage,ChatMessage
from websocket import WebSocketApp
from functools import partial
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
methods = (RoomStatsMessage,RoomDataSyncMessage,RoomRankMessage,MemberMessage,LikeMessage,ChatMessage)
# def is_chinese(uchar):
#     # 判断当前字符是否为中文字符
#     return uchar >= u'\u4e00' and uchar <= u'\u9fa5'
# def func(ustring):
#     # 输入一个字符串，输出一个字符串
#     # 输出字符串的显示宽度为指定宽度（非域宽）
#     width = 30 * 3
#     # 将20改为你想要的显示宽度（默认全角）
#     # 注意显示宽度应当大于字符串中字符个数
#     for uchar in ustring:
#         width -= 3 if is_chinese(uchar) else 2
#     return ustring + ' ' * int(width / 2) if width % 2 == 0 else ustring + '\u3000' + ' ' * int((width - 3) / 2)
# cur = ""
# conn = ""
# last_time = time.time()
# def creat_db(db_config):
#     global conn
#     global cur
#     # 建立连接对象 **将字典中的数据分别传参
#     conn = pymysql.connect(**db_config)
#     # 创建游标对象 利用游标对象去操作
#     cur = conn.cursor()
# def save(users,users_id,comments):
#     date = now_to_date()
#     users_id = str(users_id)
#     # 创建sql语句
#     sql = f"INSERT INTO all_respond (user,user_id,comment,date) VALUES ('{users}','{users_id}','{comments}','{date}')"
#     # 使用游标对象
#     res = cur.execute(sql)
#     if res > 0:
#         # print(f"执行成功: 已执行 {res} 条数据")
#         pass
#     else:
#         print("执行失败")
#     # 提交数据
#     conn.commit()
# def now_to_date(format_string="%Y-%m-%d %H:%M:%S"):
#     time_stamp = int(time.time())
#     time_array = time.localtime(time_stamp)
#     str_date = time.strftime(format_string, time_array)
#     return str_date
# def on_open(ws):
#     db_config = {
#         "host": "localhost",
#         "user": "root",
#         "passwd": "root",
#         "db": "ointment_interaction",
#         "port": 3306
#     }
#     creat_db(db_config)
#     print(conn)
#     print(cur)
#     print("on_open",ws)
# def on_message(ws,message):
#     global last_time
#     if time.time() - last_time > 100:
#         db_config = {
#             "host": "localhost",
#             "user": "root",
#             "passwd": "root",
#             "db": "ointment_interaction",
#             "port": 3306
#         }
#         creat_db(db_config)
#         last_time = time.time()
#     #接收抖音数据
#     # print("on_message", message)
#     #反序列化第一步
#     frame = PushFrame()
#     frame.ParseFromString(message)
#     # print("on_message: frame", frame)
#     # 反序列化第二步 对payload在做解压缩与反序列化
#     origin_bytes = gzip.decompress(frame.payload)
#     res = Response()
#     res.ParseFromString(origin_bytes)
#     #返回ack
#     if res.need_ack:
#         s = PushFrame()
#         s.payload_type = 'ack'
#         s.payload = res.internal_ext.encode("utf-8")
#         s.LogID = frame.LogID
#         ws.send(s.SerializeToString())
#     # print("on_message: res", res)
#     for mes in res.messages:
#         method = re.findall("Webcast(\w*)", mes.method)[0]
#         # print(method)
#         for me in methods:
#             sme = re.findall("\.([^']*)", str(me))[0]
#             # print("sme:",sme)
#             if method == sme:
#                 obj = me()
#                 obj.ParseFromString(mes.payload)
#                 # print("on_message: obj", obj)
#                 if method == "ChatMessage":
#                     username = obj.users[0].nickname
#                     bullet_chat = obj.content
#                     date = now_to_date()
#                     print("{} {}: {}".format(date,username,bullet_chat))
#                     save(username, obj.users[0].id, bullet_chat)
#                     with open(r"C:\Users\a2038\Desktop\弹幕.txt","a",encoding="utf-8") as f:
#                         f.write("{}: {}\n".format(username,bullet_chat))
#                 break
#     # print("*"*50)
# def on_error(ws,message):
#     # print(conn)
#     # print(cur)
#     print("on_error", ws,message)
#     db_config = {
#         "host": "localhost",
#         "user": "root",
#         "passwd": "root",
#         "db": "ointment_interaction",
#         "port": 3306
#     }
#     creat_db(db_config)
# def on_close(ws,*args,**kwargs):
#     cur.close()
#     conn.close()
#     print("结束")
#     pass
# # def run():
# #     #向抖音发送web请求链接
# #     ws = WebSocketApp(
# #         url="123",
# #         hearder="123",
# #         cookie="",
# #         on_open=on_open,
# #         on_message=on_message,
# #         on_error=on_error,
# #         on_close=on_close,
# #     )
# #     ws.run_forever()
# def get_room_id(url):
#     cookies = {
#         '__ac_nonce': '0687296ec00954a39ad17',
#     }
#
#     headers = {
#         'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0',
#     }
#
#     response = requests.get(url, cookies=cookies, headers=headers)
#     ttwid = response.cookies.get_dict()['ttwid']
#     room_id = re.findall(r'\\"roomId\\":\\"(\d+)\\"', response.text)[0]
#     return room_id,ttwid
# if __name__ == '__main__':
#     #1 获取room_id和ttwid
#     url = 'https://live.douyin.com/328707151106'
#     room_id, ttwid = get_room_id(url)
#     print(room_id, ttwid)
#     #2 获得sign值
#         # with open('signature.js', 'r',encoding="utf-8",errors='replace') as f:
#         #     sign = execjs.compile(f.read()).call("get_sign",room_id)
#         #     print("sign:"+sign)
#     #3 基于websocket实现长链接请求
#     # wss_url=""
#     wss_url="wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1753275083704_r-7530259138081718601_d-7530259142376685569_u-1_h-7530258651958728226&internal_ext=internal_src:dim|wss_push_room_id:7530257095174654730|wss_push_did:7504174646494316041|first_req_ms:1753275083606|fetch_time:1753275083704|seq:1|wss_info:0-1753275083704-0-0|wrds_v:7530259138081731988&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7530257095174654730&heartbeatDuration=0&signature=6M5ae8YShx2PFfb2"
#     # wss_url="wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=r-7530252420752869258_d-7530252425047834625_u-1_h-7530248922317791507_t-1753273520598&internal_ext=internal_src:dim|wss_push_room_id:7530242062881409830|wss_push_did:7504174646494316041|first_req_ms:1753273520501|fetch_time:1753273520598|seq:1|wss_info:0-1753273520598-0-0|wrds_v:7530252399278049325&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7530242062881409830&heartbeatDuration=0&signature=fgK6lxl48whH78CC"
#     # wss_url = "wss://webcast100-ws-web-lq.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1753250592125_r-7530153950037699724_d-7530153928562835457_u-1_h-7530151919823741961&internal_ext=internal_src:dim|wss_push_room_id:7530097097308719881|wss_push_did:7504174646494316041|first_req_ms:1753250591979|fetch_time:1753250592125|seq:1|wss_info:0-1753250592125-0-0|wrds_v:7530153915677940716&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7530097097308719881&heartbeatDuration=0&signature=6Mdg+huWAlRKDrPt"
#     # wss_url = "wss://webcast100-ws-web-lq.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=u-7530000877403242496_h-7530000996853281058_t-1753215041548_r-7530001263950397053_d-7530000795798863873&internal_ext=internal_src:dim|wss_push_room_id:7529944372574538559|wss_push_did:7528879877827823154|first_req_ms:1753215041439|fetch_time:1753215041548|seq:1|wss_info:0-1753215041548-0-0|wrds_v:7530001263950299857&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7528879877827823154&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7529944372574538559&heartbeatDuration=0&signature=fKkV79qjjNO6QH5K"
#     # wss_url=f'wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=h-7526651891430923520_t-1752435238618_r-7526652035568045100_d-7526652031273009155_u-7526652014093139968&internal_ext=internal_src:dim|wss_push_room_id:{room_id}|wss_push_did:7504174646494316041|first_req_ms:1752435238519|fetch_time:1752435238618|seq:1|wss_info:0-1752435238618-0-0|wrds_v:7526652035567978807&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id={room_id}&heartbeatDuration=0&signature=fKkV79qjjNO6QH5K'
#     # wss_url=f'wss://webcast100-ws-web-lq.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1753205036773_r-7529958292802524027_d-1_u-1_fh-7529957925713356583&internal_ext=internal_src:dim|wss_push_room_id:7529921262626409231|wss_push_did:7528879877827823154|first_req_ms:1753205036691|fetch_time:1753205036773|seq:1|wss_info:0-1753205036773-0-0|wrds_v:7529958279917603286&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7528879877827823154&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7529921262626409231&heartbeatDuration=0&signature=6Kka79qCjNOiVhv2'
#     ws = WebSocketApp(
#         url=wss_url,
#         # 东方甄选 url = "wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1752606358427_r-7527386977487516702_d-7527386981781733382_u-1_h-7527386009241403175&internal_ext=internal_src:dim|wss_push_room_id:7526071434494479123|wss_push_did:7504174646494316041|first_req_ms:1752606358334|fetch_time:1752606358427|seq:1|wss_info:0-1752606358427-0-0|wrds_v:7527386973191800655&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7526071434494479123&heartbeatDuration=0&signature=6KQ/qKUiCyPZAV6j",
#         # url = "wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1752615807350_r-7527427573524607654_d-7527427556337778691_u-1_h-7527427459945802534&internal_ext=internal_src:dim|wss_push_room_id:7523512639729814314|wss_push_did:7504174646494316041|first_req_ms:1752615807264|fetch_time:1752615807350|seq:1|wss_info:0-1752615807350-0-0|wrds_v:7527427552042811920&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7523512639729814314&heartbeatDuration=0&signature=6Mui7rEMZKa6F7HT",
#         header={
#             'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0'
#         },
#         cookie=f"ttwid={ttwid}",
#         on_open=on_open,
#         on_message=on_message,
#         on_error=on_error,
#         on_close=on_close,
#     )
#     ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})


class DouyinLiveMonitor:
    def __init__(self, db_config,live_id,wss_url):
        self.db_config = db_config
        self.live_url = f'https://live.douyin.com/{live_id}'
        self.wss_url = wss_url
        self.conn = None
        self.cur = None
        self.last_time = time.time()

    def creat_db(self):
        # 建立连接对象 **将字典中的数据分别传参
        self.conn = pymysql.connect(**self.db_config)
        # 创建游标对象 利用游标对象去操作
        self.cur = self.conn.cursor()

    def save(self, users, users_id, comments):
        date = self.now_to_date()
        users_id = str(users_id)
        # 创建sql语句
        sql = f"INSERT INTO all_respond (user,user_id,comment,date) VALUES ('{users}','{users_id}','{comments}','{date}')"
        # 使用游标对象
        res = self.cur.execute(sql)
        if res > 0:
            # print(f"执行成功: 已执行 {res} 条数据")
            pass
        else:
            print("执行失败")
        # 提交数据
        self.conn.commit()

    @staticmethod
    def now_to_date(format_string="%Y-%m-%d %H:%M:%S"):
        time_stamp = int(time.time())
        time_array = time.localtime(time_stamp)
        str_date = time.strftime(format_string, time_array)
        return str_date

    def on_open(self, ws):
        print(self.now_to_date(), "连接开始")
        print("on_open", ws)
        self.creat_db()

    def on_message(self, ws, message):
        if time.time() - self.last_time > 100:
            self.creat_db()
            self.last_time = time.time()

        # 接收抖音数据
        frame = PushFrame()
        frame.ParseFromString(message)

        # 反序列化第二步 对payload在做解压缩与反序列化
        origin_bytes = gzip.decompress(frame.payload)
        res = Response()
        res.ParseFromString(origin_bytes)

        # 返回ack
        if res.need_ack:
            s = PushFrame()
            s.payload_type = 'ack'
            s.payload = res.internal_ext.encode("utf-8")
            s.LogID = frame.LogID
            ws.send(s.SerializeToString())

        # 处理消息
        for mes in res.messages:
            method = re.findall("Webcast(\w*)", mes.method)[0]
            for me in methods:
                sme = re.findall("\.([^']*)", str(me))[0]
                if method == sme:
                    obj = me()
                    obj.ParseFromString(mes.payload)
                    if method == "ChatMessage":
                        username = obj.users[0].nickname
                        bullet_chat = obj.content
                        date = self.now_to_date()
                        #打印数据
                        # print("{} {}: {}".format(date, username, bullet_chat))
                        #保存数据到txt与数据库中
                        self.save(username, obj.users[0].id, bullet_chat)
                        with open(r"C:\Users\a2038\Desktop\弹幕.txt", "a", encoding="utf-8") as f:
                            f.write("{} {}: {}\n".format(date,username, bullet_chat))
                    break

    def on_error(self, ws, message):
        print(self.now_to_date(),"出现错误")
        print("on_error", ws, message)
        self.creat_db()

    def on_close(self, ws, *args, **kwargs):
        print(self.now_to_date(),"连接将要关闭")
        if self.cur:
            self.cur.close()
        if self.conn:
            self.conn.close()
        print("----------连接已关闭----------")

    def get_room_id(self, url):
        cookies = {
            '__ac_nonce': '0687296ec00954a39ad17',
        }

        headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0',
        }

        response = requests.get(url, cookies=cookies, headers=headers)
        ttwid = response.cookies.get_dict()['ttwid']
        room_id = re.findall(r'\\"roomId\\":\\"(\d+)\\"', response.text)[0]
        return room_id, ttwid

    def start_monitoring(self):
        # 1 获取room_id和ttwid
        room_id, ttwid = self.get_room_id(self.live_url)
        print(room_id, ttwid)
        # 2 获得sign值（这里保留原代码结构，但注释掉了实际调用）
        # with open('signature.js', 'r',encoding="utf-8",errors='replace') as f:
        #     sign = execjs.compile(f.read()).call("get_sign",room_id)
        #     print("sign:"+sign)
        # 3 基于websocket实现长链接请求
        # 这里使用示例URL，实际应用中可能需要动态生成
        # wss_url = "wss://webcast100-ws-web-hl.douyin.com/webcast/im/push/v2/?app_name=douyin_web&version_code=180800&webcast_sdk_version=1.0.14-beta.0&update_version_code=1.0.14-beta.0&compress=gzip&device_platform=web&cookie_enabled=true&screen_width=1707&screen_height=960&browser_language=zh-CN&browser_platform=Win32&browser_name=Mozilla&browser_version=5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/138.0.0.0%20Safari/537.36%20Edg/138.0.0.0&browser_online=true&tz_name=Asia/Shanghai&cursor=t-1753275083704_r-7530259138081718601_d-7530259142376685569_u-1_h-7530258651958728226&internal_ext=internal_src:dim|wss_push_room_id:7530257095174654730|wss_push_did:7504174646494316041|first_req_ms:1753275083606|fetch_time:1753275083704|seq:1|wss_info:0-1753275083704-0-0|wrds_v:7530259138081731988&host=https://live.douyin.com&aid=6383&live_id=1&did_rule=3&endpoint=live_pc&support_wrds=1&user_unique_id=7504174646494316041&im_path=/webcast/im/fetch/&identity=audience&need_persist_msg_count=15&insert_task_id=&live_reason=&room_id=7530257095174654730&heartbeatDuration=0&signature=6M5ae8YShx2PFfb2"
        ws = WebSocketApp(
            url=self.wss_url,
            header={
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0'
            },
            cookie=f"ttwid={ttwid}",
            on_open=self.on_open,
            on_message=self.on_message,
            on_error=self.on_error,
            on_close=self.on_close,
        )
        ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})


if __name__ == '__main__':
    db_config = {
        "host": "localhost",
        "user": "root",
        "passwd": "root",
        "db": "ointment_interaction",
        "port": 3306
    }
    live_id = input("请输入直播间ID: ")
    wss_url = input("请输入wss_url: ")
    # print(live_id)
    # print(wss_url)
    monitor = DouyinLiveMonitor(db_config,live_id,wss_url)
    monitor.start_monitoring()
